package com.bcbim.authentication.user.service;

import com.bcbim.authentication.user.mapper.UserMapper;
import com.bcbim.authentication_interface.user.dao.UserDAO;
import com.bcbim.authentication_interface.user.dao.UserRoleDAO;
import com.bcbim.authentication_interface.user.dto.UserDTO;
import com.bcbim.authentication_interface.user.dto.UserListDTO;
import com.bcbim.authentication_interface.user.po.User;
import com.bcbim.authentication_interface.user.service.UserService;
import com.bcbim.authentication_interface.user.vo.UserVO;
import com.bcbim.common.sys.Code;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description: 用户service实现类
 * @Author haoshuai
 * @Date 2020/9/11
 * @Version V1.0
 **/
@Slf4j
@Service(timeout = 60 * 1000, group = "authentication", version = "1.0.0")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

//    @Override
//    public User getUserByUsername(String username) {
//        return userMapper.getUserByUsername(username);
//    }

    /**
     * @Description: 更新最后登录时间
     * @Param: username
     * @Return:
     * @Author: ye
     * @Date: 2021/7/6
     */
    @Override
    public void updateLastLoginTime(String username) {
        userMapper.updateLastLoginTime(username);
    }


    @Override
    public UserDTO getUserByUsername(String username) {
        return userMapper.getUserByUsername(username);
    }

    @Override
    public UserDTO getUserByNickname(String nickName) {
        return userMapper.getUserByNickname(nickName);
    }

    /**
     * @Description: 用户列表
     * @Param: UserQuery
     * @Return: List<UserVO>
     * @Author: ye
     * @Date: 2020/11/30
     */
    @Override
    public List<UserVO> listUser(UserListDTO userListDTO) {
        return userMapper.listUser(userListDTO);
    }

    /**
     * @Description: 用户总数
     * @Param: nickname
     * @Return: int
     * @Author: ye
     * @Date: 2020/11/30
     */
    @Override
    public int listUserCount(UserListDTO userListDTO) {
        return userMapper.listUserCount(userListDTO);
    }

    /**
     * @Description: 新建用户
     * @Param: UserDO
     * @Return: int
     * @Author: ye
     * @Date: 2020/11/30
     */
    @Override
    public int saveUser(UserDAO userDAO) {
        return userMapper.saveUser(userDAO);
    }

    /**
     * @Description: 删除用户
     * @Param: usernames
     * @Return:
     * @Author: ye
     * @Date: 2020/11/30
     */
    @Override
    public int removeUser(String id, String del) {
        return userMapper.removeUser(id, del);
    }

    /**
     * @Description: 编辑更新用户
     * @Param: UserDO
     * @Return:
     * @Author: ye
     * @Date: 2020/11/30
     */
    @Override
    public int updateUser(UserDAO userDAO) {
        return userMapper.updateUser(userDAO);
    }

    /**
     * @Description: 用户名校验
     * @Param: username
     * @Return: int
     * @Author: ye
     * @Date: 2020/12/2
     */
    @Override
    public int usernameCheck(String username) {
        return userMapper.usernameCheck(username);
    }

    /**
     * @Description: 清除用户角色
     * @Param: id
     * @Return:
     * @Author: ye
     * @Date: 2021/7/6
     */
    @Override
    public void clearUserRole(String id) {
        userMapper.clearUserRole(id);
    }

    /**
     * @Description: 保存用户角色信息
     * @Param: List<RoleUserDO>
     * @Return:
     * @Author: ye
     * @Date: 2021/7/6
     */
    @Override
    public void saveUserRole(List<UserRoleDAO> list) {
        userMapper.saveUserRole(list);
    }

    /**
     * @return List<Code>
     * @Description 查询所有角色
     * @Author XueHao
     * @Date 2021/8/23
     */
    @Override
    public List<Code> selectRole(String roleName) {
        return userMapper.selectRole(roleName);
    }

    /**
     * 重置密码
     *
     * @param id       id
     * @param password password
     * @return int
     * @author XueHao
     * @date 2021/12/2
     */
    @Override
    public int resetPassword(String id, String password) {
        return userMapper.resetPassword(id, password);
    }

    /**
     * 查询用户详情
     *
     * @param id id
     * @return UserVO
     * @author XueHao
     * @date 2022/1/14
     */
    @Override
    public UserVO getUser(String id) {
        return userMapper.getUser(id);
    }

    /**
     * 检查旧密码
     *
     * @param id
     * @param oldPassword
     * @author xuehao
     * @createDate 2022/3/16 14:00
     * @retuen int
     */
    @Override
    public int checkOldPassword(String id, String oldPassword) {
        return userMapper.checkOldPassword(id, oldPassword);
    }

    /**
     * 查询用户拥有的平台
     *
     * @param userId
     * @author xuehao
     * @createDate 2022/3/18 9:38
     * @retuen String
     */
    @Override
    public List<Code> selectApplicationPlatformByUserId(String userId) {
        return userMapper.selectApplicationPlatformByUserId(userId);
    }

    /**
     * @Description: 查询用户角色
     * @Param: username
     * @Return: ReturnMsg
     * @Author: ye
     * @Date: 2021/7/6
     */
    @Override
    public List<Code> getUserRole(String userId) {
        return userMapper.getUserRole(userId);
    }

    /**
     * 判断用户角色数量
     *
     * @param roleId
     * @author xuehao
     * @createDate 2022/4/18 15:13
     * @retuen int
     */
    @Override
    public int checkRoleCount(String roleId) {
        return userMapper.checkRoleCount(roleId);
    }
}
